package edu.java.texbooks.scjp.threads.test18;

import java.util.Random;

public class PrintTask implements Runnable {

	// --- Instance Variables --------------------------------------------------
	private String name = null;
	private int sleepTime = 0;

	public String getName() {
		return name;
	}

	public PrintTask(String name) {
		this.name = name;
		sleepTime = new Random().nextInt(5000);
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + " starts...");

		try {
			System.out.println(Thread.currentThread().getName()
					+ " goes to sleep for " + sleepTime + " milliseconds.");
			Thread.sleep(sleepTime);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName() + " ends...");

	}

}
